//
//  IdCardAuthSuccessVC.swift
//  身份认证信息成功
//
//  Created by 千策万划-mini on 2025/5/6.
//

import Foundation

class IdCardAuthSuccessVC: BaseTableVC {
    
    var productCode: String = ""
    var name: String = ""
    var idCode: String = ""
    var birth: String = ""
    
    // MARK: - lazy
    lazy var navView: BaseNavView = {
        let result = BaseNavView()
        result.resetNavBackTitle(title: "", rightView: nil)
        result.leftTop = XY(0, 0)
        result.blockBack = { [weak self] in
            guard let self = self else { return }
            self.viewDetainment.show()
        }
        return result
    }()
    lazy var viewContent: IdCardAuthSuccessContentView = {
        let result = IdCardAuthSuccessContentView()
        result.resetView(name: name, number: idCode, birth: birth)
        return result
    }()
    lazy var btnNext: UIButton = {
        let result = UIButton()
        result.widthHeight = XY(W(284), 58)
        result.setBackgroundImage(UIImage(named: "icon_bottom_btn_bg"), for: .normal)
        result.centerXBottom = XY(SCREEN_WIDTH / 2, SCREEN_HEIGHT - max(LEFT_MARGIN, getBottomSafeAreaHeight()))
        result.tag = 1
        result.addTarget(self, action: #selector(btnClick(_:)), for: .touchUpInside)

        let label = OutlineLabel()
        label.resetView(
            title: "OK",
            textColor: COLOR_WHITE(),
            font: UIFont.customExtraBoldFont(size: 20),
            shadowColor: UIColor(hex: "#004600"),
            outlineColor: UIColor(hex: "#1B4506")
        )
        label.centerXCenterY = XY(result.width / 2, result.height / 2)
        result.addSubview(label)
        return result
    }()
    
    // MARK: - viewDidLoad
    override func viewDidLoad() {
        super.viewDidLoad()
        
        configUI()
    }
    
    func configUI() {
        view.addSubview(navView)
        view.addSubview(btnNext)
        tableView.tableHeaderView = viewContent
    }
    
    // MARK: - 点击事件
    @objc func btnClick(_ sender: UIControl) {
        feedback()
        sender.addClickAnimate()
        switch sender.tag {
        case 1:
            requestNext()
            break
        default:
            break
        }
    }
    
    // MARK: - request
    func requestNext() {
        HomeRequestApi.productDetail(productCode: self.productCode) { request, responseData in
            guard let res = responseData as? [String: Any] else {return}
            if let model = ModelProductDetail.deserialize(from: res) {
                GlobalMethod.authNext(type: model.decides.died, productCode: self.productCode, orderCode: model.fiercely.hurriedly)
            }
        } failure: { request, error in
            
        }
    }
}
